package com.lhn;

import com.lhn.dao.OrderDao;
import com.lhn.factory.OrderDaoFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author lhn
 * @date 2024-08-15 21:07
 */

public class AppForInstanceOrder {
    public static void main(String[] args) {
        //通过工厂的方式实例化对象
        OrderDao orderDao = OrderDaoFactory.getOrderDao();
        System.out.println("orderDao = " + orderDao);
        orderDao.save();

        //通过Spring容器使用工厂创建对象
        ApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml");
        OrderDao orderDao1 = (OrderDao) ctx.getBean("orderDao");
        System.out.println("orderDao1 = " + orderDao1);
        orderDao1.save();
    }
}
